package com.weetop.cfw.base.presenter.imp

import com.weetop.cfw.base.presenter.SearchPresenter
import com.weetop.cfw.base.view.BaseView
import com.weetop.cfw.base.view.SearchView
import com.weetop.cfw.bean.PopularSearchBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.home_page.activity.SearchActivity
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils

class SearchPresenterImp(var searchView: SearchView? = null):SearchPresenter {
    /**
     * 获取热门搜索数据
     */
    override fun getPopularSearchList(searchActivity: SearchActivity, popularSearchType: String) {
        searchActivity.showLoadingDialog(searchActivity,"正在获取热门搜索数据...")
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().getPopularSearchData(popularSearchType),searchActivity,object:RxJavaCallBack<PopularSearchBean>(){

            override fun onSuccess(t: PopularSearchBean?) {
                searchActivity.dismissLoadingDialog()
                searchView?.getPopularSearchDataSuccess(t)
            }

            override fun onRequestError(t: PopularSearchBean?) {
                super.onRequestError(t)
                searchActivity.dismissLoadingDialog()
            }

            override fun onErrorResponse(throwable: Throwable?) {
                super.onErrorResponse(throwable)
                searchActivity.dismissLoadingDialog()
            }

        })
    }

    /**
     * 绑定
     */
    override fun attachView(baseView: BaseView) {
        searchView = baseView as? SearchView
    }

    /**
     * 解绑
     */
    override fun detachView() {
       searchView = null
    }
}